#include<bits/stdc++.h>
#define LL long long 
using namespace std;
const LL N=2e6+5;
const LL mod=1e9+7;
LL n,k,x,y,sz[N],ans;
vector<LL>v[N];
LL ksm(LL x,LL y)
{
	LL ans=1;
	while(y)
	{
		if(y&1)ans=ans*x%mod;
		x=x*x%mod,y>>=1; 
	}
	return ans;
}
void dfs(LL x,LL fa)
{
	sz[x]=1;
	for(LL i:v[x])
	{
		if(i==fa)continue;
		dfs(i,x),sz[x]+=sz[i];
		ans=(ans+sz[i]*(n-sz[i])%mod)%mod;
	}
}
int main()
{
	cin>>n>>k;
	if(k&1)
	{
		puts("1");
		return 0;
	}
	for(int i=1;i<=n-1;i++)
	{
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1,0);
	cout<<(ans*ksm(n*(n-1)/2%mod,mod-2)%mod+1)%mod;
	return 0;
}
	
